

#include <iostream>

#include <algorithm>

#include <cstring>

using namespace std;

#define maxn 100001

#define maxk 17

const int INF = 1<<30;

int n,k;

int value[maxk], price[maxn], sum[maxn];

int maxans = -1;

int dp[1<<maxk];

//dp[i]表示当前硬币选择状态为i时，能买到的最大商品数

inline bool ChoosedCurrent(int state, int current){

	return state & (1<<current);

}

inline int StateNotChooseCurrent(int state, int current){

	return state ^ (1<<current);

}

inline int find(int value){

	return upper_bound(sum+1, sum+n+1, value)-sum-1;

}

int main(){

	cin>>k>>n;

	for(int i=0;i<k;i++)

		cin>>value[i];

	for(int i=1;i<=n;i++){

		cin>>price[i];

		//求商品价格前缀和

		sum[i] = sum[i-1]+price[i];

	}

	

	for(int state=1; state<=(1<<k)-1; state++){

		for(int current=0; current<k; current++){

			if(ChoosedCurrent(state, current)){

				dp[state] = max(dp[state], find( \

					sum[dp[StateNotChooseCurrent(state, current)]]+value[current]));

				//在前缀和中查找第一个大于 sum[若不选该硬币我能买到的商品数]+value[当前硬币面额]

				//find函数返回的值就是我们当前硬币状态所能买到的最大商品数

			}

		}

	}

	for(int state=1; state<=(1<<k)-1; state++){

		if(dp[state]==n)	//买完了

		{

			int ans=0;

			for(int current=0; current<k; current++){

				if(!ChoosedCurrent(state, current)){

					//我们要的是剩余面额而非总花费，因此要加没选上的

					ans += value[current];

				}

			}

			maxans = max(ans, maxans);

		}

	}

	

	cout<<maxans<<endl;

	

	return 0;

}

